package com.triptogether.utils.androidsystem;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

/**
 * Wrapper for the {@link SharedPreferences} for easily get values from the applications preferences.
 */
public class SharedPreferencesUtils {
	
	private static final String PROPERTY_KEY_USER_LOGED_IN = "user_loged_in";
	private static final String PROPERTY_KEY_USER_ID = "user_id";
	
	private static SharedPreferences getDefaultSharedPreferences(Context context) {
		return PreferenceManager.getDefaultSharedPreferences(context);
	}
	
	public static void setUserLogedIn(Context context, boolean userLogedIn) {
		Editor editor = getDefaultSharedPreferences(context).edit();
		editor.putBoolean(PROPERTY_KEY_USER_LOGED_IN, userLogedIn);
		editor.commit();
	}
	
	public static boolean getUserLogedIn(Context context) {
		return getDefaultSharedPreferences(context).getBoolean(PROPERTY_KEY_USER_LOGED_IN, false);
	}
	
	public static void setUserId(Context context, String userId) {
		Editor editor = getDefaultSharedPreferences(context).edit();
		editor.putString(PROPERTY_KEY_USER_ID, userId);
		editor.commit();
	}
	
	public static String getUserId(Context context) {
		return getDefaultSharedPreferences(context).getString(PROPERTY_KEY_USER_ID, "");
	}
}
